$(function () {

    var divNum = 1;

    $('button.next').click(function () {
    	if(divNum === 1) {
        	if (!validatePhoneDiv()) {
                return false;
            }
            ajaxVerifyCode();
            if (!ajaxVerifyCodeResult) {
                return false;
            }
        } else if (divNum === 2){
            if (!validateNewPasswordDiv()) {
                return false;
            }
            ajaxResetByMobile();
            if (!ajaxResetByMobileResult) {
                return false;
            }
        }
        divNum++;
        changeDiv();
    });
    $('button.prev').click(function () {
        divNum--;
        changeDiv();
    });

    function changeDiv() {
        if (divNum === 1) {
            $('#main').css('display', 'block');
            $('#mainset').css('display', 'none');
            $('#mainsuccess').css('display', 'none');
            certity_click();
        } else if (divNum === 2) {
        	$('#main').css('display', 'none');
            $('#mainset').css('display', 'block');
            $('#mainsuccess').css('display', 'none');
            set_click();
        } else if (divNum === 3) {
        	$('#main').css('display', 'none');
            $('#mainset').css('display', 'none');
            $('#mainsuccess').css('display', 'block');
            success_click();
        }
    }

    /**
     * 前台验证 手机信息页面
     * */
    function validatePhoneDiv(){
        if(!(/^1\d{10}$/.test($("#mobile").val()))){
            alert("请填写正确的手机号码");
            $("#mobile")[0].focus();
            return false;
        }
        if($("#mobileVerifyCode").val()==""){
            alert("请填写手机动态码");
            $("#mobileVerifyCode")[0].focus();
            return false;
        }
        if($("#verifyCode_phone").val()==""){
            alert("请填写验证码");
            $("#verifyCode_phone")[0].focus();
            return false;
        }
        return true;
    }

    /**
     * 前台验证 新密码输入是否正确
     * */
    function validateNewPasswordDiv(){
        if($("#newPassword").val()===$("#newPasswordRedo").val()){
            return true;
        }else{
            alert("请填写密码不一致");
            $("#newPasswordRedo")[0].focus();
            return false;
        }
    }

    function certity_click(){
    	 $(this).css({"background-image":"url(${newframe}/template/images/loginimgs/step1.png)","color":"#566278"}).siblings('.set').css({"background-image":"url(${newframe}/template/images/loginimgs/step2_none.png)","color":"#b3b3b3"}).siblings('.success').css({"background-image":"url(${newframe}/template/images/loginimgs/step3_none.png)","color":"#b3b3b3"});
         $('.certity .active').css('left','0');
         $('#main').css('display','block').siblings('#mainset').css('display','none').siblings('#mainsuccess').css('display','none');

    }
    function set_click(){
    	 $(this).css({"background-image":"url(${newframe}/template/images/loginimgs/step2.png)","color":"#566278"}).siblings('.certity').css({"background-image":"url(${newframe}/template/images/loginimgs/step1_none.png)","color":"#b3b3b3"}).siblings('.success').css({"background-image":"url(${newframe}/template/images/loginimgs/step3_none.png)","color":"#b3b3b3"});
         $('.certity .active').css('left','192'+'px');
         $('#mainset').css('display','block').siblings('#main').css('display','none').siblings('#mainsuccess').css('display','none');
    }
    function success_click(){
    	$(this).css({"background-image":"url(${newframe}/template/images/loginimgs/step3.png)","color":"#566278"}).siblings('.certity').css({"background-image":"url(${newframe}/template/images/loginimgs/step1_none.png)","color":"#b3b3b3"}).siblings('.set').css({"background-image":"url(${newframe}/template/images/loginimgs/step2_none.png)","color":"#b3b3b3"});
        $('.certity .active').css('left','376'+'px');
        $('#mainsuccess').css('display','block').siblings('#main').css('display','none').siblings('#mainset').css('display','none');
    }
    $('#title .step .certity').click(function(){
    	certity_click();
    });
    $('#title .step .set').click(function(){
    	set_click();
    });
    $('#title .step .success').click(function(){
    	success_click();
    });

	$('.next button').mouseenter(function(){
		$(this).css("background",'#35c990');
	}).mouseleave(function(){
		$(this).css("background","#e6e6e6");
	});
	$('.nextstep .prev').mouseenter(function(){
        $(this).css("background",'#35c990');
	}).mouseleave(function(){
        $(this).css("background","#e6e6e6");
    });
    $('.nextstep .next').mouseenter(function(){
        $(this).css("background",'#35c990');
    }).mouseleave(function(){
        $(this).css("background","#e6e6e6");
    });
});